package com.artron.mediaartron.ui.widget;

import android.content.Context;
import android.support.v4.view.ViewPager;
import android.util.AttributeSet;
import android.util.Log;
import android.view.MotionEvent;
import android.view.ViewConfiguration;

/**
 * Class description here
 *
 * @author doing
 * @version 1.0.0
 * @since 2017-09-22.
 */

public class CustomHorizontalViewPager extends ViewPager {

    public CustomHorizontalViewPager(Context context) {
        super(context);
    }

    public CustomHorizontalViewPager(Context context, AttributeSet attrs) {
        super(context, attrs);
    }

    private float mPreviousX;
    private float mPreviousY;

    @Override
    public boolean onInterceptTouchEvent(MotionEvent event) {
        boolean intercept = super.onInterceptTouchEvent(event);

        float moveX = 0.f;
        float moveY = 0.f;
        switch (event.getAction()) {
            case MotionEvent.ACTION_DOWN:
                mPreviousX = event.getX();
                mPreviousY = event.getY();
                break;
            case MotionEvent.ACTION_MOVE:
                moveX = Math.abs(event.getX() - mPreviousX);
                moveY = Math.abs(event.getY() - mPreviousY);
                break;
        }


        int scaledTouchSlop = ViewConfiguration.get(getContext()).getScaledTouchSlop();
        return moveX > scaledTouchSlop / 2 && moveY < moveX || intercept;
    }


}
